package logic

import (
	"context"
	"fmt"
	"shop/model/mysql"
	"shop/shoprpc/internal/svc"
	"shop/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopAddLogic {
	return &ShopAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopAddLogic) ShopAdd(in *shoprpc.ShopAddRequest) (*shoprpc.ShopAddResponse, error) {
	// todo: add your logic here and delete this line

	products := mysql.Products{
		Shopname:  in.Shopname,
		Shopimage: in.Shopimage,
		Price:     in.Price,
		Stock:     in.Stock,
		Userid:    in.Userid,
	}
	err := mysql.DB.Create(&products).Error
	if err != nil {
		return nil, fmt.Errorf("商品添加失败")
	}

	return &shoprpc.ShopAddResponse{
		Id: int64(products.ID),
	}, nil
}
